% Chapter 2. Section 5.

\section{Automating everything - CMake}
\label{autotools}

As we already mentioned makefiles are usually really large to be created by hand. That's why software developers use tools that automate makefile generation process. That phase of software building is called \textit { configuration}. During the configuration phase the configurator (a single tool or a tool set) collects all the necessary information and does all the necessary checks. For example it checks if the compiler is there, finds out it's name, searches for particular versions of necessary libraries, finds some system paths, and processes project's configuration files. After that phase makefiles are generated using some templates or some raw makefiles. 

One of such automation tool sets is GNU Autotools. It contains several tools: \textit { Autoconf, Automake, Libtool.} 

GNU Autoconf deals with a file named \textit { configure.ac}. As a result we get a script file called \textit { configure}. That script later must be executed by the user. It processes all the Makefile.in files and generates the corresponding Makefiles.

GNU Automake processes Makefile.am files and creates the portable Makefile.in files. Later these files are being processed by the \textit { configure} script. After all the configuration steps are finished, the project can be build using GNU Make utility.

Of course GNU Autotools are really great in doing their job. But still there is another tool which would be more convenient for the software developers. It's the {\bf CMake - Cross-Platform Makefile Generator} tool. All the necessary information on using this tool and the tool itself can be found on their official web site: \textit { www.cmake.org}. CMake, regardless it's name, is a configuration tool. It must be executed as a first step of the software build process. As output it can generate makefiles or project files depending on the platform. 

To use the CMake tool in all the folders of the project a file must be added named \textit { CMakeLists.txt}. These files should contain the configuration commands and settings for the CMake tool.

\subsection {Using CMake}
Let's consider a project having a little bit complicated structure: \textit { root folder, bin, include, lib} and \textit { src} folders. The source files are situated in the \textit { src} folder, include files are in the \textit { include} folder. During the build process all the library files must be generated in the \textit { lib} folder and all the executable files must be stored in the \textit { bin} folder. In the listing \ref {cmake} there is a CMakeLists.txt file presented, which must be located in the project root folder to satisfy our needs concerning the build process.

\lstinputlisting[label=cmake ,caption=Using CMake,language=make]{Sources/chapter2/CMakeLists.txt}

